﻿using System.Collections.Generic;
using System.Security.Principal;

namespace Authorization
{
    public class UserPrincipal : IPrincipal 
    {
        private List<string> roles;
 
        public UserPrincipal()
        {
            this.roles = new List<string>();
        }

        public UserPrincipal(IIdentity identity, List<string> roles)
        {
            this.Identity = identity;
            this.roles = roles;
        }

        #region IPrincipal Members

        public IIdentity Identity { get; set; }

        public bool IsInRole(string role)
        {
            foreach (string userRole in roles)
            {
                if(userRole == role)
                {
                    return true;
                }
            }

            return false;
        }

        #endregion
    }
}